 <template>
	<view class="content">
		<!-- 实时选择器 -->
		<form @submit="formSubmit">
			<view class="item">通用写法：</view>
			<select-lay :zindex="1211" :value="tval" name="name" placeholder="请选择您想填报的专业" :options="datalist"
				@selectitem="selectitem">
			</select-lay>
			<view style="height:40rpx">---------------</view>
		</form>
		
		<button @click='myfunc'>查看已选专业</button>		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				//模拟数据列表
				datalist: [],
				//模拟初始数据
				tval: "value2",
			}
		},
		onLoad() {
			this.getMajors()
		},
		onReady() {
			this.datalist = [{
					label: "label11111",
					value: "value1"
				},
				// // 加上这里就有了初始数据.
				// {
				//     label: "label2333",
				//     value: "value2"
				// },
			];

		},
		methods: {
			myfunc(){
				console.log('=== tval:', this.tval);
			},
			
			async getMajors() {
				const res = await this.$myRequest({
				  method: 'GET',
				  url: '/api/myconf/Major/'
				})
				var data = res.data.result.data
				console.log(data);
				
				this.datalist = []
				for(var i = 0; i < data.length; i++){
					 var dc = {
						label: data[i]['name'],
						value: data[i]['name'],
					}
					this.datalist.push(dc)
				}
				console.log('~~~ this.datalist:', this.datalist)
			},
			
			formSubmit(e) {
				console.log('form发生了submit事件，携带数据为：' + JSON.stringify(e.detail.value))
			},
			selectitem(index, item) {
				console.log(item)
				if (index >= 0) {
					this.tval = item.value;
				} else {
					this.tval = ""
				}
			},
		}
	}
 </script>